package main;
import java.util.List;
import java.util.Random;

public class RandomProvider {
    private static Random random = new Random();

    public static boolean chance(double p) {
        if (p < 0 || p > 1) {
            throw new IllegalArgumentException("p should be between 0 and 1");
        }

        return random.nextDouble() <= p;
    }

    public static int roll(int value, double success) {
        int result = 0;
        for (int i = 0; i < value; i++) {
            if (RandomProvider.chance(success)) {
                result++;
            }
        }
        return result;
    }
    
    public static double roll(double value) {
        if (value <= 0) {
            throw new IllegalArgumentException("value should be positive");
        }
        
        return random.nextDouble() * value;
    }
    
    public static int roll(int value) {
        if (value <= 0) {
            throw new IllegalArgumentException("value should be positive");
        }
        
        return random.nextInt(value) + 1;
    }

    public static<T> T chooseRandom(List<T> items) {
        return items.get(random.nextInt(items.size()));
    }
}
